#include <iostream>
using namespace std;
template<class p>
class Stack
{
    p* stack;
    p top;
public:
    Stack()
    {
        stack = new p[10];
        top = 0;
    }
    void push(p x)
    {
        stack[top] = x;
        top++;
    }
    bool stackempty()
    {
        if (top == 0)
            return true;
        else
            return false;
    }
    p pop()
    {
        top--;
        return stack[top];
    }
};
int main()
{
    Stack<int > A;
    Stack<char> B;
    int x, n;
    char ch;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        A.push(x);
    }
    while (!A.stackempty())
    {
        x = A.pop();
        cout << x << " ";
    }
    cout << endl;
    int m = 0;
    cin >> m;
    n = m;
    char f[10] = { 0 };
    cin >> f;
    for (int i = 0; i < n; i++)
    {
        B.push(f[i]);
    }
    while (!B.stackempty())
    {
        char f = B.pop();
        cout << f << ' ';
    }
        return 0;
}